home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Apple Script
/
OSAX
/
Mount Volume
/
MountVolOSAX.c
< prev
next >
Wrap
Text File
|
1993-11-01
|
4KB
|
197 lines
#define SystemSevenOrLater 1
/*
c mountvolosax.c -b -b2 -b3 -sym full
link -t osax -c ascr -rt osax=0 -m MOUNTAFPVOLUME ∂
-sg "AEVTaevtmntv" -ra "AEVTaevtmntv"=resSysHeap,resLocked ∂
MountVolOSAX.c.o "{Libraries}Interface.o" "{CLibraries}StdCLib.o" ∂
-o MountVol -sym full
*/
#ifndef __STRING__
#include <String.h>
#endif
#ifndef __MEMORY__
#include <Memory.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#ifndef __STRINGS__
#include <Strings.h>
#endif
#ifndef __ERRORS__
#include <Errors.h>
#endif
#ifndef __APPLEEVENTS__
#include <AppleEvents.h>
#endif
enum
{
// flag values
kNormalMountFlags = 0, kInhibitMsgFlags
};
typedef unsigned char Str8[9];
typedef struct
{
short length;
VolumeType media;
short flags;
SignedByte nbpInterval;
SignedByte nbpCount;
short uamType;
short zoneNameOffset;
short serverNameOffset;
short volNameOffset;
short userNameOffset;
short userPasswordOffset;
short volPasswordOffset;
Str31 zoneName;
Str31 serverName;
Str27 volName;
Str31 userName;
Str8 userPassword;
Str8 volPassword;
} AFPVolMountInfoRec;
typedef AFPVolMountInfoRec* AFPVolMountPtr;
void SetErrorValue(AEDesc* result, short error);
OSErr VolumeMount(AFPVolMountPtr pc);
OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString);
pascal OSErr MountAFPVolume(AppleEvent *in, AppleEvent *out, long)
{
OSErr error;
short uamType = kNoUserAuthentication;
AFPVolMountPtr pb;
pb = (AFPVolMountPtr) NewPtrClear(sizeof(AFPVolMountInfoRec));
if (!pb)
{
error = MemError();
goto exit;
}
error = Get1Parameter(in, 'ZONE', 31, pb->zoneName);
if (error) goto exit;
error = Get1Parameter(in, 'SRVR', 31, pb->serverName);
if (error) goto exit;
error = Get1Parameter(in, 'VOLM', 27, pb->volName);
if (error) goto exit;
error = Get1Parameter(in, 'USER', 31, pb->userName);
if (!error)
{
error = Get1Parameter(in, 'PASS', 8, pb->userPassword);
uamType = kPassword;
}
pb->length = sizeof(AFPVolMountInfoRec);
pb->media = AppleShareMediaType;
pb->flags = kNormalMountFlags;
pb->nbpInterval = 2;
pb->nbpCount = 2;
pb->uamType = uamType;
pb->zoneNameOffset = 24;
pb->serverNameOffset = 56;
pb->volNameOffset = 88;
pb->userNameOffset = 116;
pb->userPasswordOffset = 148;
pb->volPasswordOffset = 157;
error = VolumeMount(pb);
SetErrorValue(out, error);
error = noErr;
exit:
return error;
}
OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString)
{
DescType theType;
OSErr error;
Size paramSize;
error = AESizeOfParam(in, type, &theType, ¶mSize);
if (error) goto exit;
error = AEGetParamPtr(in, type, typeChar, &theType, (Ptr) theString, size, ¶mSize);
if (error) goto exit;
c2pstr((char *)theString);
exit:
return error;
}
OSErr VolumeMount(AFPVolMountPtr pc)
{
OSErr error;
IOParam pb;
pb.ioBuffer = (Ptr)pc;
error = PBVolumeMount((ParmBlkPtr) & pb);
return error;
}
void SetErrorValue(AppleEvent* result, short error)
{
Str255 theError;
short length;
switch (error)
{
case noErr:
strcpy(theError, "0");
break;
case notOpenErr:
strcpy(theError, "AppleTalk not open. Please turn on AppleTalk™ in the Chooser");
break;
case nsvErr:
strcpy(theError, "The volume does not exist.");
break;
case paramErr:
strcpy(theError, "Parameter Error!");
break;
case extFSErr:
strcpy(theError, "Appleshare is not installed! Please move AppleShare into the Extensions folder.");
break;
case afpNoServer:
strcpy(theError, "The specified server doesn’t exist.");
break;
case afpUserNotAuth:
strcpy(theError, "Unable to authenticate user.");
break;
case afpPwdExpiredErr:
strcpy(theError, "The password has expired.");
break;
case afpAccessDenied:
strcpy(theError, "Access denied. Update the password.");
break;
case aspNoMoreSess:
case aspServerBusy:
case aspTooMany:
strcpy(theError, "There are too many users logged into the server. Please try again later.");
break;
default:
strcpy(theError, "A network error occurred! Please make sure that EtherTalk is selected in the Network Control Panel.");
break;
}
length = strlen(theError);
AEPutParamPtr(result, keyDirectObject,typeChar,(Ptr) theError, length);
}